WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
capture_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Forward declarations for node templates
22namespace wolf
23{
24class FrameBase;
25class FeatureBase;
26} // namespace wolf
27
28// Wolf includes
29#include "core/common/wolf.h"
32
33// std includes
34
35namespace wolf
36{
41{
42 friend class FeatureBase;
43 friend class FactorBase;
44 friend class FrameBase;
45
46 private:
47 FrameBaseWPtr frame_ptr_;
48 FeatureBasePtrList feature_list_;
49 SensorBaseWPtr sensor_ptr_;
50
51 static unsigned int capture_id_count_;
52
53 protected:
54 unsigned int capture_id_;
56
59 void setProblem(ProblemPtr _problem) override final;
60
61 public:
77 CaptureBase(const std::string& _type,
78 const TimeStamp& _ts,
79 SensorBasePtr _sensor_ptr = nullptr,
80 const TypeComposite& _state_types = {},
81 const VectorComposite& _state_vectors = {},
82 const PriorComposite& _state_priors = {});
83
84 ~CaptureBase() override = default;
85
90 void remove(bool viral_remove_parent_without_children = false) override;
91
94 bool hasChildren() const override;
95
103 virtual FactorBasePtr emplaceDriftFactor(CaptureBasePtr _capture_origin, char _key, bool _apply_loss_function);
104
107 virtual bool isMotion() const;
108
113 bool process();
114
115 unsigned int id() const override;
116
119 TimeStamp getTimeStamp() const;
120
123 void setTimeStamp(const TimeStamp& _ts);
124
127 void setTimeStampToNow();
128
131 FrameBaseConstPtr getFrame() const;
132
135 FrameBasePtr getFrame();
136
137 private:
140 void setFrame(const FrameBasePtr _frm_ptr);
141
142 public:
145 FeatureBaseConstPtrList getFeatureList() const;
146
149 FeatureBasePtrList getFeatureList();
150
153 bool hasFeature(const FeatureBaseConstPtr& _feature) const;
154
157 FactorBaseConstPtrList getFactorList() const;
158
161 FactorBasePtrList getFactorList();
162
165 void getFactorList(FactorBaseConstPtrList& _fac_list) const;
166
169 void getFactorList(FactorBasePtrList& _fac_list);
170
173 SensorBaseConstPtr getSensor() const;
174
177 SensorBasePtr getSensor();
178
181 virtual void setSensor(const SensorBasePtr sensor_ptr);
182
183 public:
184 // State blocks
188 StateBlockConstPtr getStateBlock(const char& _key) const override;
189
193 StateBlockPtr getStateBlock(const char& _key) override;
194
197 StateBlockConstPtr getSensorP() const;
198
201 StateBlockPtr getSensorP();
202
205 StateBlockConstPtr getSensorO() const;
206
209 StateBlockPtr getSensorO();
210
213 StateBlockConstPtr getSensorIntrinsic() const;
214
217 StateBlockPtr getSensorIntrinsic();
218
219 void fix() override;
220 void unfix() override;
221
226 void link(FrameBasePtr _frm_ptr);
227
234 template <typename classType, typename... T>
235 static std::shared_ptr<classType> emplace(FrameBasePtr _frm_ptr, T&&... all);
236
246 virtual void printHeader(int depth,
247 bool factored_by,
248 bool metric,
249 bool state_blocks,
250 std::ostream& stream,
251 std::string _tabs = "") const;
252
262 void print(int depth,
263 bool factored_by,
264 bool metric,
265 bool state_blocks,
266 std::ostream& stream = std::cout,
267 std::string _tabs = "") const;
268
276 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
277
286 bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
287
288 private:
291 FeatureBasePtr addFeature(FeatureBasePtr _ft_ptr);
292
295 void removeFeature(FeatureBasePtr _ft_ptr);
296
297 public:
300 CaptureBasePtr shared_from_this_capture();
301
304 CaptureBaseConstPtr shared_from_this_capture() const;
305};
306
307} // namespace wolf
308
313
314namespace wolf
315{
316inline bool CaptureBase::isMotion() const
317{
318 return false;
319}
320
321template <typename classType, typename... T>
322std::shared_ptr<classType> CaptureBase::emplace(FrameBasePtr _frm_ptr, T&&... all)
323{
324 std::shared_ptr<classType> cpt = std::make_shared<classType>(std::forward<T>(all)...);
325 cpt->emplacePriors();
326 cpt->link(_frm_ptr);
327 return cpt;
328}
329
330inline StateBlockConstPtr CaptureBase::getSensorP() const
331{
332 return getStateBlock('P');
333}
334
335inline StateBlockPtr CaptureBase::getSensorP()
336{
337 return getStateBlock('P');
338}
339
340inline StateBlockConstPtr CaptureBase::getSensorO() const
341{
342 return getStateBlock('O');
343}
344
345inline StateBlockPtr CaptureBase::getSensorO()
346{
347 return getStateBlock('O');
348}
349
350inline StateBlockConstPtr CaptureBase::getSensorIntrinsic() const
351{
352 return getStateBlock('I');
353}
354
356{
357 return getStateBlock('I');
358}
359
360inline unsigned int CaptureBase::id() const
361{
362 return capture_id_;
363}
364
365inline FrameBaseConstPtr CaptureBase::getFrame() const
366{
367 if (frame_ptr_.expired())
368 return nullptr;
369 else
370 return frame_ptr_.lock();
371}
372
373inline FrameBasePtr CaptureBase::getFrame()
374{
375 if (frame_ptr_.expired())
376 return nullptr;
377 else
378 return frame_ptr_.lock();
379}
380
381inline void CaptureBase::setFrame(const FrameBasePtr _frm_ptr)
382{
383 frame_ptr_ = _frm_ptr;
384}
385
386inline FeatureBaseConstPtrList CaptureBase::getFeatureList() const
387{
388 FeatureBaseConstPtrList list_const;
389 for (auto&& obj_ptr : feature_list_) list_const.push_back(obj_ptr);
390 return list_const;
391}
392
393inline FeatureBasePtrList CaptureBase::getFeatureList()
394{
395 return feature_list_;
396}
397
399{
400 return time_stamp_;
401}
402
403inline SensorBaseConstPtr CaptureBase::getSensor() const
404{
405 return sensor_ptr_.lock();
406}
407
408inline SensorBasePtr CaptureBase::getSensor()
409{
410 return sensor_ptr_.lock();
411}
412
413inline void CaptureBase::setSensor(const SensorBasePtr sensor_ptr)
414{
415 sensor_ptr_ = sensor_ptr;
416}
417
419{
420 assert(_ts.ok() && "Setting an invalid timestamp to a capture!");
421 time_stamp_ = _ts;
422}
423
425{
427}
428
430{
431 return std::static_pointer_cast<CaptureBase>(shared_from_this());
432}
433
434inline CaptureBaseConstPtr CaptureBase::shared_from_this_capture() const
435{
436 return std::static_pointer_cast<const CaptureBase>(shared_from_this());
437}
438
439} // namespace wolf
Base class of captures: a sensor measurement taken at a time stamp, linked to a frame,...
Definition: capture_base.h:41
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Prints the information of this node (not of its children)
Definition: capture_base.cpp:268
bool process()
Processes the capture with its sensor (see SensorBase::process())
Definition: capture_base.cpp:151
StateBlockConstPtr getSensorO() const
Returns the sensor state block of key 'O' (see getStateBlock())
Definition: capture_base.h:340
unsigned int id() const override
Returns the id of the node, unique among the nodes of its category.
Definition: capture_base.h:360
TimeStamp time_stamp_
Time stamp.
Definition: capture_base.h:55
StateBlockConstPtr getSensorP() const
Returns the sensor state block of key 'P' (see getStateBlock())
Definition: capture_base.h:330
void fix() override
Fixes all the state blocks.
Definition: capture_base.cpp:227
void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Prints this node and, depending on the depth, its children.
Definition: capture_base.cpp:296
FrameBaseConstPtr getFrame() const
Returns the frame the capture belongs to (nullptr if none)
Definition: capture_base.h:365
StateBlockConstPtr getStateBlock(const char &_key) const override
Returns the state block of a key: the sensor's one if it is a static sensor state,...
Definition: capture_base.cpp:201
FeatureBaseConstPtrList getFeatureList() const
Returns the features of the capture.
Definition: capture_base.h:386
unsigned int capture_id_
Capture id, unique among captures.
Definition: capture_base.h:54
CaptureBase(const std::string &_type, const TimeStamp &_ts, SensorBasePtr _sensor_ptr=nullptr, const TypeComposite &_state_types={}, const VectorComposite &_state_vectors={}, const PriorComposite &_state_priors={})
Constructor.
Definition: capture_base.cpp:29
SensorBaseConstPtr getSensor() const
Returns the sensor that produced the capture (nullptr if unknown)
Definition: capture_base.h:403
void setTimeStamp(const TimeStamp &_ts)
Sets the time stamp.
Definition: capture_base.h:418
bool hasChildren() const override
Returns whether the capture has children: features or factors constraining it.
Definition: capture_base.cpp:109
void setProblem(ProblemPtr _problem) override final
Sets the problem to the capture and its features, and updates the last capture of the sensor.
Definition: capture_base.cpp:252
FactorBaseConstPtrList getFactorList() const
Returns the factors of all the features of the capture.
Definition: capture_base.cpp:170
virtual FactorBasePtr emplaceDriftFactor(CaptureBasePtr _capture_origin, char _key, bool _apply_loss_function)
Emplaces a FactorBlockDifference with zero difference between the state _key of this capture and _cap...
Definition: capture_base.cpp:114
virtual void setSensor(const SensorBasePtr sensor_ptr)
Sets the sensor that produced the capture.
Definition: capture_base.h:413
void unfix() override
Unfixes all the state blocks.
Definition: capture_base.cpp:232
StateBlockConstPtr getSensorIntrinsic() const
Returns the sensor state block of key 'I' (see getStateBlock())
Definition: capture_base.h:350
virtual bool isMotion() const
Returns whether the capture is a motion capture (CaptureMotion)
Definition: capture_base.h:316
void link(FrameBasePtr _frm_ptr)
Links the capture to a frame.
Definition: capture_base.cpp:237
~CaptureBase() override=default
void remove(bool viral_remove_parent_without_children=false) override
Removes the capture, its features and their factors.
Definition: capture_base.cpp:73
bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node and its children, composing the log.
Definition: capture_base.cpp:378
CaptureBasePtr shared_from_this_capture()
Returns a shared pointer to this capture.
Definition: capture_base.h:429
void setTimeStampToNow()
Sets the time stamp to the current time.
Definition: capture_base.h:424
TimeStamp getTimeStamp() const
Returns the time stamp.
Definition: capture_base.h:398
bool hasFeature(const FeatureBaseConstPtr &_feature) const
Returns whether the feature belongs to the capture.
Definition: capture_base.cpp:196
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node (not of its children)
Definition: capture_base.cpp:309
static std::shared_ptr< classType > emplace(FrameBasePtr _frm_ptr, T &&... all)
Creates a capture of class classType, emplaces its priors and links it to the frame.
Definition: capture_base.h:322
Log of a consistency check: whether it is consistent and the explanation of the inconsistencies.
Definition: check_log.h:30
Base class of factors: a constraint between state blocks of one or more nodes, given a measurement an...
Definition: factor_base.h:73
Base class of features: a measurement with its uncertainty, extracted from a capture,...
Definition: feature_base.h:40
Base class of frames: the states of the robot at a time stamp, in the trajectory, with the captures t...
Definition: frame_base.h:40
Base class of the nodes having state blocks (sensors, frames, captures and landmarks)
Definition: node_state_blocks.h:36
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
bool ok() const
Returns whether the time stamp has a valid value.
Definition: time_stamp.h:214
void setToNow()
Sets the time stamp to now (valid)
Definition: time_stamp.cpp:69
Composite of state vectors.
Definition: vector_composite.h:29
Definition: capture_base.h:23
Composite< Prior > PriorComposite
Definition: prior_composite.h:87